package com.dubito.dose.feature.medicationconfirm.navigation

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.dubito.dose.core.navigation.DoseNavigationDestination
import com.dubito.dose.domain.model.Medication
import com.dubito.dose.feature.medicationconfirm.MedicationConfirmRoute

/**
 * author: LiLiang
 * createTime: 2022/9/4-1:28
 * remark:
 **/

const val MEDICATION = "medication"

object MedicationConfirmDestination : DoseNavigationDestination {
    override val route: String
        get() = "medication_confirm_route"
    override val destination: String
        get() = "medication_confirm_destination"
}

fun NavGraphBuilder.medicationConfirmGraph(
    navController: NavController,
    bottomBarVisibility: MutableState<Boolean>,
    fabVisibility: MutableState<Boolean>,
    onBackClicked: () -> Unit,
    navigateToHome: () -> Unit
) {
    composable(MedicationConfirmDestination.route) {
        LaunchedEffect(null) {
            bottomBarVisibility.value = false
            fabVisibility.value = false
        }
        val medication =
            navController.previousBackStackEntry?.arguments?.getParcelable<Medication>(MEDICATION)
        MedicationConfirmRoute(medication, onBackClicked, navigateToHome)
    }
}